package com.yazdankhah.dal;

import java.sql.Connection;
import org.apache.log4j.Logger;

/**
 * This class creates a table object and does DML operations on a table.
 * Author:	Ahmad Yazdankhah
 */
public class Table {
  
  private final String tableName;
  
  private static final Logger logger = Logger.getLogger(Table.class);


  public Table(String tableName) {
    this.tableName = tableName;
  } //constructor
  
  
  public boolean deleteAll(boolean isTransaction) {
    
    DalSession dSession = DalSession.getDalSession();
    Connection conn = dSession.getDSConnection();
    
    if (conn == null) {
      logger.error("Connection is null! Couldn't get a connection from datasource!");
      return false;
    }
    
    boolean res = SqlUtil.deleteAll(conn, tableName);
    
    if (!isTransaction)
      dSession.closeConnection(conn);
    
    return res;
    
  } //method
  
  
//........................ M A I N   M E T H O D ............................//
  /**
   * This main method is just for testing this class.
   *
   * @param args the arguments
   */
  public static void main(String[] args) {

    //testprintTable();

  } //main method

}
